/*
 * @lc app=leetcode.cn id=566 lang=typescript
 *
 * [566] 重塑矩阵
 */

// @lc code=start
function matrixReshape(mat: number[][], r: number, c: number): number[][] {
    const row = mat.length;
    const col = mat[0].length;
    if (row * col !== r * c) {
        return mat
    }
    const result = new Array(r).fill(0).map(() => new Array(c).fill(0))
    for (let i = 0; i < row * col; i++) {

        result[Math.floor(i / c)][i % c] = mat[Math.floor(i / col)][i % col]
    }
    // console.log(result)
    return result

};

// matrixReshape([[1, 2], [3, 4], [5, 6]], 2, 3);
// @lc code=end

